/*
Janet Putnam
CS 362
Assignment 3
Unit Test 1 - Unit Test of whoseTurn

Include the following lines in make file:

unittest1:  unittest1.c dominion.o rngs.o
	gcc -o unittest1 -g unittest1.c dominion.o rngs.o $(CFLAGS)

*/

#include "dominion/dominion.h"
#include "dominion/dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "dominion/rngs.h"
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>

/* Copy of function from dominion.c for reference purposes, can be removed from code
int whoseTurn(struct gameState *state) {
  return state->whoseTurn;
}
*/

/* Copy of struct gameState from dominion.h for reference purposes, can be removed from code 
struct gameState {
  int numPlayers; //number of players
  int supplyCount[treasure_map+1];  //this is the amount of a specific type of card given a specific number.
  int embargoTokens[treasure_map+1];
  int outpostPlayed;
  int outpostTurn;
  int whoseTurn;
  int phase;
  int numActions; /* Starts at 1 each turn */ /*
  int coins; /* Use as you see fit! */ /*
  int numBuys; /* Starts at 1 each turn */  /*
  int hand[MAX_PLAYERS][MAX_HAND];
  int handCount[MAX_PLAYERS];
  int deck[MAX_PLAYERS][MAX_DECK];
  int deckCount[MAX_PLAYERS];
  int discard[MAX_PLAYERS][MAX_DECK];
  int discardCount[MAX_PLAYERS];
  int playedCards[MAX_DECK];
  int playedCardCount;
};
*/
int whoseTurn(struct gameState *state);

int whoseTurnTest(int print_pass)
{
	int i;
	int result;
	int j;
	//setup initial struct gameState
	struct gameState G;
	
	memset(&G, 0, sizeof(struct gameState));
	
	//select cards in game
	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy};

	//initialize gameState struct with initial value for number of players
	initializeGame(MAX_PLAYERS, k, 4, &G);
	
	//test that number of players was set correctly
	if(G.numPlayers != MAX_PLAYERS)
	{
		printf("FAIL:  Number of players not set correctly in structure.\n");
	}
	else
	{
		if(print_pass == 0)
		{
			printf("PASS:  Number of players set correctly in structure.\n");
		}
	}
	
	for(i=1; i<=(G.numPlayers); i++)
	{
			//set G->whoseTurn to i
			G.whoseTurn = i;
			
			//pull value of turn
			j = G.whoseTurn;
			
			//call function being tested
			result = whoseTurn(&G);
			
			//compare return value to input value and manual pulled value
			if (i!=j)
			{
				printf("FAIL:  Player %d value initially not set correctly in structure.\n", i);
			}
			else
			{
				if(print_pass == 0)
				{
					printf("PASS:  Player %d value initially set correctly in structure.\n", i);
				}
			}
			
			if (i!=result)
			{
				printf("FAIL:  Player %d value not correctly read from structure.\n", i);
			}
			else
			{
				if(print_pass == 0)
				{
					printf("PASS:  Player %d value correctly read from structure.\n", i);
				}
			}
			if (j!=result)
			{
				printf("FAIL:  Player %d value not correctly read from structure.\n", i);
			}
			else
			{
				if(print_pass == 0)
				{
					printf("PASS:  Player %d value correctly read from structure.\n", i);
				}
			}
			
			
	
	}
	
	return 0;


}


int main(int argc, char **argv)
{	
	int print_pass;
	//if print_pass = 0, then results will print for passing tests.
	//if print_pass = 1, then results will not print for passing tests.
	//regardless of print_pass state, failing tests will print results.
	
	print_pass = atoi(argv[1]);
	if ((print_pass != 1 ) || (print_pass != 0))
	{
		print_pass = 0;
	}
	
	whoseTurnTest(print_pass);
	return 0;
}
	
	